package ibm.cognos.imt;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 12/26/13
 * Time: 2:45 PM
 * To change this template use File | Settings | File Templates.
 */
public class ReportHtmlUtil {
    private String source;
    private Document document;

//    public static String sampleHtml() {
//        return "<html lang=\"en\">\n" +
//                "<head>\n" +
//                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n" +
//                "<meta name=\"Copyright\" content=\"Licensed Materials - Property of IBM; IBM Cognos Products: rsvp; (C) Copyright IBM Corp. 2005, 2010; US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.\">\n" +
//                "<link xmlns:rsext=\"xalan://com.cognos.reportserver.ext.RSExt\" rel=\"stylesheet\" type=\"text/css\" href=\"http://9.119.141.234:88/ibmcognos/skins/corporate/viewer/QSRVSelection.css\"><link xmlns:rsext=\"xalan://com.cognos.reportserver.ext.RSExt\" rel=\"stylesheet\" type=\"text/css\" href=\"http://9.119.141.234:88/ibmcognos/schemas/GlobalReportStyles_10.css\">\n" +
//                "<title></title>\n" +
//                "<script xmlns:rsext=\"xalan://com.cognos.reportserver.ext.RSExt\" language=\"javascript\" type=\"text/javascript\">\n" +
//                "function isIE()\n" +
//                "{\n" +
//                "return (navigator.userAgent.indexOf('MSIE') != -1);\n" +
//                "}\n" +
//                "\n" +
//                "function getNavVer()\n" +
//                "{\n" +
//                "if (isIE()){\n" +
//                "var temp=navigator.userAgent.split('MSIE');\n" +
//                "return parseFloat(temp[1]);\n" +
//                "} else {\n" +
//                "\n" +
//                "var temp = navigator.userAgent.split('\\/');\n" +
//                "return parseFloat(temp[temp.length - 1]);\n" +
//                "}\n" +
//                "}\n" +
//                "\n" +
//                "function preprint()\n" +
//                "{\n" +
//                "if (isIE() && getNavVer() >= 5.5 && getNavVer() < 7.0) {\n" +
//                "var alltags = document.images;\n" +
//                "\n" +
//                "for (var i=0; i < alltags.length; i++){\n" +
//                "if (alltags[i].className == 'ch'){\n" +
//                "if (alltags[i].srcbackup){\n" +
//                "alltags[i].src = alltags[i].srcbackup;\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "\n" +
//                "function postprint()\n" +
//                "{\n" +
//                "if (isIE() && getNavVer() >= 5.5 && getNavVer() < 7.0) {\n" +
//                "var alltags = document.images;\n" +
//                "\n" +
//                "for (var i=0; i < alltags.length; i++){\n" +
//                "if (alltags[i].className == 'ch'){\n" +
//                "if (alltags[i].srcbackup){\n" +
//                "alltags[i].src = 'http://9.119.141.234:88/ibmcognos/ps/images/space.gif';\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "\n" +
//                "if (isIE() && getNavVer() >= 5.5 && getNavVer() < 7.0) {\n" +
//                "window.onbeforeprint=preprint;\n" +
//                "window.onafterprint=postprint;\n" +
//                "}\n" +
//                "\n" +
//                "function displayChart(imageName, imgSrc, useScale, isImage)\n" +
//                "{\n" +
//                "if (isIE() && getNavVer() >= 5.5 && getNavVer() < 7.0) {\n" +
//                "var oImg = document.images[imageName];\n" +
//                "var strOldImg;\n" +
//                "if (imgSrc.length > 1){\n" +
//                "strOldImg = imgSrc;\n" +
//                "} else {\n" +
//                "strOldImg = oImg.src;\n" +
//                "}\n" +
//                "\n" +
//                "var imgURL = strOldImg;\n" +
//                "oImg.srcbackup = imgURL;\n" +
//                "\n" +
//                "\n" +
//                "\n" +
//                "strOldImg = strOldImg.replace(new RegExp(/%/g), \"%25\");\n" +
//                "// BUG: IE's display filter parser is broken and incorrectly sees any closing\n" +
//                "// brackets contained in an href as the end of a filter expression .. so we need to escape them\n" +
//                "strOldImg = strOldImg.replace(/\\x28/g, \"%28\");\n" +
//                "strOldImg = strOldImg.replace(/\\x29/g, \"%29\");\n" +
//                "\n" +
//                "var strSizing = useScale ? \"scale\" : \"crop\";\n" +
//                "if ( isImage ) {\n" +
//                "strSizing = \"image\";\n" +
//                "}\n" +
//                "\n" +
//                "oImg.src = 'http://9.119.141.234:88/ibmcognos/ps/images/space.gif';\n" +
//                "oImg.style.filter = \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='\" + strOldImg + \"',sizingMethod='\" + strSizing + \"');\";\n" +
//                "\n" +
//                "} else {\n" +
//                "if (imgSrc.length > 1){\n" +
//                "document.images[imageName].src = imgSrc;\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "</script><script xmlns:rsext=\"xalan://com.cognos.reportserver.ext.RSExt\" type=\"text/javascript\">\n" +
//                "var gCognosViewerId = \"_THIS_\";\n" +
//                "var sLocation = document.location.search;\n" +
//                "if (sLocation.match(/cv\\.id=([^&?]*)/))\n" +
//                "{\n" +
//                "gCognosViewerId = RegExp.$1;\n" +
//                "}\n" +
//                "\n" +
//                "function getCognosViewer()\n" +
//                "{\n" +
//                "var cognosViewer = null;\n" +
//                "try\n" +
//                "{\n" +
//                "cognosViewer = eval(\"parent.oCV\" + gCognosViewerId);\n" +
//                "}\n" +
//                "catch(e)\n" +
//                "{\n" +
//                "cognosViewer = null; \n" +
//                "}\n" +
//                "\n" +
//                "return cognosViewer;\n" +
//                "}\n" +
//                "\n" +
//                "\n" +
//                "function getSelectionController()\n" +
//                "{\n" +
//                "var selectionController = null;\n" +
//                "\n" +
//                "var cognosViewer = getCognosViewer();\n" +
//                "if(cognosViewer != null)\n" +
//                "{\n" +
//                "selectionController = cognosViewer.getSelectionController();\n" +
//                "}\n" +
//                "\n" +
//                "return selectionController;\n" +
//                "};\n" +
//                "\n" +
//                "\n" +
//                "function onLoadEvent(evt)\n" +
//                "{\n" +
//                "\n" +
//                "var selectionController = getSelectionController();\n" +
//                "if(selectionController != null)\n" +
//                "{\n" +
//                "selectionController.addMetaData({\"1\":{\"q\":\"Query7\"},\"2\":{\"r\":\"Revenue\",\"dtype\":0,\"drill\":0,\"usage\":2,\"q\":1},\"3\":{\"i\":\"[gosales].[Sales].[Revenue]\"},\"4\":{\"r\":\"Year\",\"dtype\":4,\"drill\":0,\"usage\":0,\"q\":1},\"5\":{\"i\":\"[Business view].[Time].[Year]\"},\"6\":{\"r\":\"Product line\",\"dtype\":45,\"drill\":0,\"usage\":0,\"q\":1},\"7\":{\"i\":\"[gosales].[Products].[Product line]\"},\"8\":{\"r\":\"Revenue\",\"dtype\":12,\"drill\":0,\"usage\":2,\"q\":1},\"9\":{\"q\":\"Query5\"},\"10\":{\"r\":\"Year\",\"dtype\":11,\"drill\":0,\"usage\":0,\"q\":9,\"level\":1},\"11\":{\"r\":\"Country\",\"dtype\":1,\"drill\":0,\"usage\":0,\"q\":9,\"level\":1},\"12\":{\"i\":\"[Business view].[Branch].[Country]\"},\"13\":{\"r\":\"Revenue\",\"dtype\":11,\"drill\":0,\"usage\":2,\"q\":9,\"level\":0}}); \n" +
//                "selectionController.addContextData({\"1\":{\"u\":\"Revenue\",\"r\":2,\"q\":1},\"2\":{\"u\":\"Year\",\"r\":4,\"q\":1},\"3\":{\"u\":\"Product line\",\"r\":6,\"q\":1},\"4\":{\"u\":\"332986338.06\",\"r\":8,\"q\":1,\"i\":3},\"5\":{\"u\":\"2004\",\"r\":4,\"q\":1,\"i\":5},\"6\":{\"u\":\"Camping Equipment\",\"r\":6,\"q\":1,\"i\":7},\"7\":{\"u\":\"153553850.98\",\"r\":8,\"q\":1,\"i\":3},\"8\":{\"u\":\"Golf Equipment\",\"r\":6,\"q\":1,\"i\":7},\"9\":{\"u\":\"36165521.07\",\"r\":8,\"q\":1,\"i\":3},\"10\":{\"u\":\"Outdoor Protection\",\"r\":6,\"q\":1,\"i\":7},\"11\":{\"u\":\"391647093.61\",\"r\":8,\"q\":1,\"i\":3},\"12\":{\"u\":\"Personal Accessories\",\"r\":6,\"q\":1,\"i\":7},\"13\":{\"u\":\"402757573.17\",\"r\":8,\"q\":1,\"i\":3},\"14\":{\"u\":\"2005\",\"r\":4,\"q\":1,\"i\":5},\"15\":{\"u\":\"168006427.07\",\"r\":8,\"q\":1,\"i\":3},\"16\":{\"u\":\"107099659.94\",\"r\":8,\"q\":1,\"i\":3},\"17\":{\"u\":\"Mountaineering Equipment\",\"r\":6,\"q\":1,\"i\":7},\"18\":{\"u\":\"25008574.08\",\"r\":8,\"q\":1,\"i\":3},\"19\":{\"u\":\"456323355.9\",\"r\":8,\"q\":1,\"i\":3},\"20\":{\"u\":\"500382422.83\",\"r\":8,\"q\":1,\"i\":3},\"21\":{\"u\":\"2006\",\"r\":4,\"q\":1,\"i\":5},\"22\":{\"u\":\"230110270.55\",\"r\":8,\"q\":1,\"i\":3},\"23\":{\"u\":\"161039823.26\",\"r\":8,\"q\":1,\"i\":3},\"24\":{\"u\":\"10349175.84\",\"r\":8,\"q\":1,\"i\":3},\"25\":{\"u\":\"594009408.42\",\"r\":8,\"q\":1,\"i\":3},\"26\":{\"u\":\"352910329.97\",\"r\":8,\"q\":1,\"i\":3},\"27\":{\"u\":\"2007\",\"r\":4,\"q\":1,\"i\":5},\"28\":{\"u\":\"174740819.29\",\"r\":8,\"q\":1,\"i\":3},\"29\":{\"u\":\"141520649.7\",\"r\":8,\"q\":1,\"i\":3},\"30\":{\"u\":\"4471025.26\",\"r\":8,\"q\":1,\"i\":3},\"31\":{\"u\":\"443693449.85\",\"r\":8,\"q\":1,\"i\":3},\"32\":{\"u\":\"2005\",\"r\":10,\"q\":9,\"i\":5},\"33\":{\"u\":\"2006\",\"r\":10,\"q\":9,\"i\":5},\"34\":{\"u\":\"2007\",\"r\":10,\"q\":9,\"i\":5},\"35\":{\"u\":\"2004\",\"r\":10,\"q\":9,\"i\":5},\"36\":{\"u\":\"Australia\",\"r\":11,\"q\":9,\"i\":12},\"37\":{\"u\":\"Austria\",\"r\":11,\"q\":9,\"i\":12},\"38\":{\"u\":\"Belgium\",\"r\":11,\"q\":9,\"i\":12},\"39\":{\"u\":\"Brazil\",\"r\":11,\"q\":9,\"i\":12},\"40\":{\"u\":\"Canada\",\"r\":11,\"q\":9,\"i\":12},\"41\":{\"u\":\"China\",\"r\":11,\"q\":9,\"i\":12},\"42\":{\"u\":\"Finland\",\"r\":11,\"q\":9,\"i\":12},\"43\":{\"u\":\"France\",\"r\":11,\"q\":9,\"i\":12},\"44\":{\"u\":\"Germany\",\"r\":11,\"q\":9,\"i\":12},\"45\":{\"u\":\"Italy\",\"r\":11,\"q\":9,\"i\":12},\"46\":{\"u\":\"Japan\",\"r\":11,\"q\":9,\"i\":12},\"47\":{\"u\":\"Korea\",\"r\":11,\"q\":9,\"i\":12},\"48\":{\"u\":\"Mexico\",\"r\":11,\"q\":9,\"i\":12},\"49\":{\"u\":\"Netherlands\",\"r\":11,\"q\":9,\"i\":12},\"50\":{\"u\":\"Singapore\",\"r\":11,\"q\":9,\"i\":12},\"51\":{\"u\":\"Spain\",\"r\":11,\"q\":9,\"i\":12},\"52\":{\"u\":\"Sweden\",\"r\":11,\"q\":9,\"i\":12},\"53\":{\"u\":\"Switzerland\",\"r\":11,\"q\":9,\"i\":12},\"54\":{\"u\":\"United Kingdom\",\"r\":11,\"q\":9,\"i\":12},\"55\":{\"u\":\"United States\",\"r\":11,\"q\":9,\"i\":12},\"56\":{\"u\":\"Year\",\"r\":10,\"q\":9,\"i\":5},\"57\":{\"u\":\"Country\",\"r\":11,\"q\":9,\"i\":12},\"58\":{\"u\":\"19270852.15\",\"r\":13,\"q\":9,\"i\":3},\"59\":{\"u\":\"38968802.62\",\"r\":13,\"q\":9,\"i\":3},\"60\":{\"u\":\"29323674.25\",\"r\":13,\"q\":9,\"i\":3},\"61\":{\"u\":\"19343686.48\",\"r\":13,\"q\":9,\"i\":3},\"62\":{\"u\":\"28348967.66\",\"r\":13,\"q\":9,\"i\":3},\"63\":{\"u\":\"21981766.43\",\"r\":13,\"q\":9,\"i\":3},\"64\":{\"u\":\"13866004.52\",\"r\":13,\"q\":9,\"i\":3},\"65\":{\"u\":\"21554248.84\",\"r\":13,\"q\":9,\"i\":3},\"66\":{\"u\":\"27345821.17\",\"r\":13,\"q\":9,\"i\":3},\"67\":{\"u\":\"19822994.69\",\"r\":13,\"q\":9,\"i\":3},\"68\":{\"u\":\"22580246.05\",\"r\":13,\"q\":9,\"i\":3},\"69\":{\"u\":\"28939868.92\",\"r\":13,\"q\":9,\"i\":3},\"70\":{\"u\":\"21447899.23\",\"r\":13,\"q\":9,\"i\":3},\"71\":{\"u\":\"17566891.21\",\"r\":13,\"q\":9,\"i\":3},\"72\":{\"u\":\"49366410.09\",\"r\":13,\"q\":9,\"i\":3},\"73\":{\"u\":\"67341094.59\",\"r\":13,\"q\":9,\"i\":3},\"74\":{\"u\":\"53511041.09\",\"r\":13,\"q\":9,\"i\":3},\"75\":{\"u\":\"41468882.87\",\"r\":13,\"q\":9,\"i\":3},\"76\":{\"u\":\"54721687.35\",\"r\":13,\"q\":9,\"i\":3},\"77\":{\"u\":\"70569951.66\",\"r\":13,\"q\":9,\"i\":3},\"78\":{\"u\":\"50570397.61\",\"r\":13,\"q\":9,\"i\":3},\"79\":{\"u\":\"48615406.63\",\"r\":13,\"q\":9,\"i\":3},\"80\":{\"u\":\"35485794.15\",\"r\":13,\"q\":9,\"i\":3},\"81\":{\"u\":\"45967540.48\",\"r\":13,\"q\":9,\"i\":3},\"82\":{\"u\":\"35396299.54\",\"r\":13,\"q\":9,\"i\":3},\"83\":{\"u\":\"27206118.41\",\"r\":13,\"q\":9,\"i\":3},\"84\":{\"u\":\"45745704.79\",\"r\":13,\"q\":9,\"i\":3},\"85\":{\"u\":\"53967275.85\",\"r\":13,\"q\":9,\"i\":3},\"86\":{\"u\":\"43928088.57\",\"r\":13,\"q\":9,\"i\":3},\"87\":{\"u\":\"50546272.09\",\"r\":13,\"q\":9,\"i\":3},\"88\":{\"u\":\"43631063.98\",\"r\":13,\"q\":9,\"i\":3},\"89\":{\"u\":\"55037217.04\",\"r\":13,\"q\":9,\"i\":3},\"90\":{\"u\":\"41352298.31\",\"r\":13,\"q\":9,\"i\":3},\"91\":{\"u\":\"41462245.81\",\"r\":13,\"q\":9,\"i\":3},\"92\":{\"u\":\"31113988.15\",\"r\":13,\"q\":9,\"i\":3},\"93\":{\"u\":\"45622153.53\",\"r\":13,\"q\":9,\"i\":3},\"94\":{\"u\":\"33788864.66\",\"r\":13,\"q\":9,\"i\":3},\"95\":{\"u\":\"22227856.92\",\"r\":13,\"q\":9,\"i\":3},\"96\":{\"u\":\"58251511.01\",\"r\":13,\"q\":9,\"i\":3},\"97\":{\"u\":\"73162203.83\",\"r\":13,\"q\":9,\"i\":3},\"98\":{\"u\":\"53138382.31\",\"r\":13,\"q\":9,\"i\":3},\"99\":{\"u\":\"52035850.83\",\"r\":13,\"q\":9,\"i\":3},\"100\":{\"u\":\"42487248.13\",\"r\":13,\"q\":9,\"i\":3},\"101\":{\"u\":\"48993648.2\",\"r\":13,\"q\":9,\"i\":3},\"102\":{\"u\":\"37861828.65\",\"r\":13,\"q\":9,\"i\":3},\"103\":{\"u\":\"34972686.75\",\"r\":13,\"q\":9,\"i\":3},\"104\":{\"u\":\"35589920.02\",\"r\":13,\"q\":9,\"i\":3},\"105\":{\"u\":\"50770840.19\",\"r\":13,\"q\":9,\"i\":3},\"106\":{\"u\":\"32341116.79\",\"r\":13,\"q\":9,\"i\":3},\"107\":{\"u\":\"22359707.9\",\"r\":13,\"q\":9,\"i\":3},\"108\":{\"u\":\"31959640.39\",\"r\":13,\"q\":9,\"i\":3},\"109\":{\"u\":\"42550836.35\",\"r\":13,\"q\":9,\"i\":3},\"110\":{\"u\":\"33459084\",\"r\":13,\"q\":9,\"i\":3},\"111\":{\"u\":\"25243944.19\",\"r\":13,\"q\":9,\"i\":3},\"112\":{\"u\":\"37519215.28\",\"r\":13,\"q\":9,\"i\":3},\"113\":{\"u\":\"43997353.59\",\"r\":13,\"q\":9,\"i\":3},\"114\":{\"u\":\"33670543.85\",\"r\":13,\"q\":9,\"i\":3},\"115\":{\"u\":\"31123033.44\",\"r\":13,\"q\":9,\"i\":3},\"116\":{\"u\":\"27822178.46\",\"r\":13,\"q\":9,\"i\":3},\"117\":{\"u\":\"41467572.14\",\"r\":13,\"q\":9,\"i\":3},\"118\":{\"u\":\"31586471.26\",\"r\":13,\"q\":9,\"i\":3},\"119\":{\"u\":\"20230164.18\",\"r\":13,\"q\":9,\"i\":3},\"120\":{\"u\":\"22770212.11\",\"r\":13,\"q\":9,\"i\":3},\"121\":{\"u\":\"28629690.81\",\"r\":13,\"q\":9,\"i\":3},\"122\":{\"u\":\"23089905.72\",\"r\":13,\"q\":9,\"i\":3},\"123\":{\"u\":\"17780084.81\",\"r\":13,\"q\":9,\"i\":3},\"124\":{\"u\":\"380789747.47\",\"r\":13,\"q\":9,\"i\":3},\"125\":{\"u\":\"482114950.82\",\"r\":13,\"q\":9,\"i\":3},\"126\":{\"u\":\"349478076.6\",\"r\":13,\"q\":9,\"i\":3},\"127\":{\"u\":\"295529033.9\",\"r\":13,\"q\":9,\"i\":3},\"128\":{\"u\":\"47515163.57\",\"r\":13,\"q\":9,\"i\":3},\"129\":{\"u\":\"57109122.24\",\"r\":13,\"q\":9,\"i\":3},\"130\":{\"u\":\"45281813.88\",\"r\":13,\"q\":9,\"i\":3},\"131\":{\"u\":\"41283644.94\",\"r\":13,\"q\":9,\"i\":3},\"132\":{\"u\":\"131677071.69\",\"r\":13,\"q\":9,\"i\":3},\"133\":{\"u\":\"164986189.21\",\"r\":13,\"q\":9,\"i\":3},\"134\":{\"u\":\"126305726.63\",\"r\":13,\"q\":9,\"i\":3},\"135\":{\"u\":\"110834974.32\",\"r\":13,\"q\":9,\"i\":3}}); \n" +
//                "selectionController.setSelectionBasedFeaturesEnabled(true);\n" +
//                "}\n" +
//                "else {\n" +
//                "setTimeout(onLoadEvent, 100);\n" +
//                "}\n" +
//                "};\n" +
//                "\n" +
//                "function onMouseMoveEvent(evt)\n" +
//                "{\n" +
//                "var selectionController = getSelectionController();\n" +
//                "if(selectionController != null)\n" +
//                "{\n" +
//                "selectionController.pageHover(evt);\n" +
//                "}\n" +
//                "};\n" +
//                "\n" +
//                "function onKeyDownEvent(evt)\n" +
//                "{\n" +
//                "var cognosViewer = getCognosViewer();\n" +
//                "if(cognosViewer != null)\n" +
//                "{\n" +
//                "cognosViewer.onKeyDown(evt);\n" +
//                "}\n" +
//                "};\n" +
//                "\n" +
//                "function onDoubleClickEvent(evt)\n" +
//                "{\n" +
//                "var selectionController = getSelectionController();\n" +
//                "if(selectionController != null)\n" +
//                "{\n" +
//                "selectionController.pageDoubleClicked(evt);\n" +
//                "}\n" +
//                "};\n" +
//                "\n" +
//                "function onContextMenuEvent(evt)\n" +
//                "{\n" +
//                "var cognosViewer = getCognosViewer();\n" +
//                "if(cognosViewer != null)\n" +
//                "{\n" +
//                "cognosViewer.dcm(evt,true);\n" +
//                "}\n" +
//                "};\n" +
//                "\n" +
//                "function preSelectNode(evt)\n" +
//                "{\n" +
//                "if (document.all) \n" +
//                "{\n" +
//                "var cognosViewer = getCognosViewer();\n" +
//                "if(cognosViewer != null)\n" +
//                "{\n" +
//                "cognosViewer.pcc(evt);\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "\n" +
//                "\n" +
//                "function onClickEvent(evt)\n" +
//                "{\n" +
//                "var cognosViewer = getCognosViewer();\n" +
//                "if(cognosViewer && cognosViewer.rvMainWnd)\n" +
//                "{\n" +
//                "cognosViewer.rvMainWnd.pageClicked(evt);\n" +
//                "}\n" +
//                "};\n" +
//                "\n" +
//                "</script><script xmlns:rsext=\"xalan://com.cognos.reportserver.ext.RSExt\" type=\"text/javascript\">\n" +
//                "var userAgent = navigator.userAgent.toLowerCase();\n" +
//                "if ( (userAgent.indexOf(\"mozilla\") > -1 && userAgent.indexOf (\"msie\") < 0)\n" +
//                "|| (userAgent.indexOf(\"firefox\") > -1))\n" +
//                "{\n" +
//                "var style = document.createElement (\"style\");\n" +
//                "\n" +
//                "style.setAttribute (\"type\", \"text/css\");\n" +
//                "\n" +
//                "var head = document.documentElement.getElementsByTagName (\"head\");\n" +
//                "\n" +
//                "if (head.length > 0)\n" +
//                "head.item (0).appendChild(style);\n" +
//                "\n" +
//                "if (document.styleSheets.length > 0)\n" +
//                "{\n" +
//                "style.sheet.insertRule (\"*[style*='text-align: right']{  text-align:-moz-right !important;  } \", 0);\n" +
//                "style.sheet.insertRule (\"*[style*='text-align: center']{  text-align:-moz-center !important;  } \", 0);\n" +
//                "}\n" +
//                "\n" +
//                "for (index = 0; index < document.styleSheets.length; index++)\n" +
//                "{\n" +
//                "var styleSheet = document.styleSheets.item (index);\n" +
//                "\n" +
//                "for (iRule = 0; iRule < styleSheet.cssRules.length; iRule++)\n" +
//                "{\n" +
//                "var rule = styleSheet.cssRules.item (iRule);\n" +
//                "\n" +
//                "if (rule.style != null)\n" +
//                "{\n" +
//                "var alignment = rule.style.getPropertyValue (\"text-align\");\n" +
//                "\n" +
//                "if (alignment != null && alignment.length > 0)\n" +
//                "{\n" +
//                "if (alignment == \"center\")\n" +
//                "rule.style.setProperty (\"text-align\", \"-moz-center\", \"important\");\n" +
//                "else if (alignment == \"right\")\n" +
//                "rule.style.setProperty (\"text-align\", \"-moz-right\", \"important\");\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "}\n" +
//                "  }\n" +
//                "</script>\n" +
//                "</head>\n" +
//                "<body \n" +
//                "onclick=\"onClickEvent(event);\" onkeydown=\"onKeyDownEvent(event);\" onload=\"onLoadEvent(event);\" onmousemove=\"onMouseMoveEvent(event);\" ondblclick=\"onDoubleClickEvent(event);\" oncontextmenu=\"onContextMenuEvent(event);\"topmargin=\"0\" leftmargin=\"0\" style=\"background-color: #FFFFFF;\">\n" +
//                "<table xmlns:rsext=\"xalan://com.cognos.reportserver.ext.RSExt\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"pg\" LID=\"Page1\"><tr class=\"tableRow\"><td class=\"pb\"><table class=\"tb\" cellpadding=\"0\"><tr class=\"tableRow\"><td class=\"tableCell\"><table style=\"border-collapse:collapse;\" class=\"ls\" LID=\"null\" cellpadding=\"0\"><tr><td class=\"c_THIS_12 lt\" cid=\"0\" uid=\"12\" name=\"c_THIS_12\" type=\"columnTitle\"><span tabIndex=\"0\" ctx=\"1\" class=\"textItem\">Revenue</span></td><td class=\"c_THIS_14 lt\" cid=\"1\" uid=\"14\" name=\"c_THIS_14\" type=\"columnTitle\"><span tabIndex=\"-1\" ctx=\"2\" class=\"textItem\">Year</span></td><td class=\"c_THIS_16 lt\" cid=\"2\" uid=\"16\" name=\"c_THIS_16\" type=\"columnTitle\"><span tabIndex=\"-1\" ctx=\"3\" class=\"textItem\">Product line</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"4:5:6\" class=\"textItem\">$332,986,338.06</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"5:4:6\" class=\"textItem\">2004</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"6:4:5\" class=\"textItem\">Camping Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"7:5:8\" class=\"textItem\">$153,553,850.98</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"5:7:8\" class=\"textItem\">2004</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"8:7:5\" class=\"textItem\">Golf Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"9:5:10\" class=\"textItem\">$36,165,521.07</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"5:9:10\" class=\"textItem\">2004</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"10:9:5\" class=\"textItem\">Outdoor Protection</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"11:5:12\" class=\"textItem\">$391,647,093.61</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"5:11:12\" class=\"textItem\">2004</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"12:11:5\" class=\"textItem\">Personal Accessories</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"13:14:6\" class=\"textItem\">$402,757,573.17</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"14:13:6\" class=\"textItem\">2005</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"6:13:14\" class=\"textItem\">Camping Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"15:14:8\" class=\"textItem\">$168,006,427.07</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"14:15:8\" class=\"textItem\">2005</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"8:15:14\" class=\"textItem\">Golf Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"16:14:17\" class=\"textItem\">$107,099,659.94</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"14:16:17\" class=\"textItem\">2005</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"17:16:14\" class=\"textItem\">Mountaineering Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"18:14:10\" class=\"textItem\">$25,008,574.08</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"14:18:10\" class=\"textItem\">2005</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"10:18:14\" class=\"textItem\">Outdoor Protection</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"19:14:12\" class=\"textItem\">$456,323,355.90</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"14:19:12\" class=\"textItem\">2005</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"12:19:14\" class=\"textItem\">Personal Accessories</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"20:21:6\" class=\"textItem\">$500,382,422.83</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"21:20:6\" class=\"textItem\">2006</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"6:20:21\" class=\"textItem\">Camping Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"22:21:8\" class=\"textItem\">$230,110,270.55</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"21:22:8\" class=\"textItem\">2006</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"8:22:21\" class=\"textItem\">Golf Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"23:21:17\" class=\"textItem\">$161,039,823.26</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"21:23:17\" class=\"textItem\">2006</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"17:23:21\" class=\"textItem\">Mountaineering Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"24:21:10\" class=\"textItem\">$10,349,175.84</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"21:24:10\" class=\"textItem\">2006</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"10:24:21\" class=\"textItem\">Outdoor Protection</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"25:21:12\" class=\"textItem\">$594,009,408.42</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"21:25:12\" class=\"textItem\">2006</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"12:25:21\" class=\"textItem\">Personal Accessories</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"26:27:6\" class=\"textItem\">$352,910,329.97</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"27:26:6\" class=\"textItem\">2007</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"6:26:27\" class=\"textItem\">Camping Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"28:27:8\" class=\"textItem\">$174,740,819.29</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"27:28:8\" class=\"textItem\">2007</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"8:28:27\" class=\"textItem\">Golf Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"29:27:17\" class=\"textItem\">$141,520,649.70</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"27:29:17\" class=\"textItem\">2007</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"17:29:27\" class=\"textItem\">Mountaineering Equipment</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"30:27:10\" class=\"textItem\">$4,471,025.26</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"27:30:10\" class=\"textItem\">2007</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"10:30:27\" class=\"textItem\">Outdoor Protection</span></td></tr><tr><td class=\"c_THIS_19 lm\" cid=\"0\" uid=\"19\" name=\"c_THIS_19\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"31:27:12\" class=\"textItem\">$443,693,449.85</span><span tabIndex=\"-1\" style=\"visibility:hidden;\" class=\"textItem\">)</span></td><td class=\"c_THIS_21 lm\" cid=\"1\" uid=\"21\" name=\"c_THIS_21\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"27:31:12\" class=\"textItem\">2007</span></td><td class=\"c_THIS_23 lm\" cid=\"2\" uid=\"23\" name=\"c_THIS_23\" type=\"datavalue\"><span tabIndex=\"-1\" ctx=\"12:31:27\" class=\"textItem\">Personal Accessories</span></td></tr></table></td><td class=\"tableCell\"></td></tr><tr class=\"tableRow\"><td class=\"tableCell\"></td><td class=\"tableCell\"><map class=\"chart_map\" LID=\"rsvptt0\" name=\"rsvptt0\"><area class=\"chart_area\" type=\"legendTitle\" shape=\"POLY\" coords=\"671, 6, 777, 6, 777, 22, 671, 22\" ctx=\"57\" tabIndex=\"-1\" isChartTitle=\"true\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 23, 770, 23, 770, 35, 688, 35\" title=\"Country = Australia\" ctx=\"36\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 36, 770, 36, 770, 49, 688, 49\" title=\"Country = Austria\" ctx=\"37\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 49, 770, 49, 770, 62, 688, 62\" title=\"Country = Belgium\" ctx=\"38\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 62, 770, 62, 770, 75, 688, 75\" title=\"Country = Brazil\" ctx=\"39\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 76, 770, 76, 770, 88, 688, 88\" title=\"Country = Canada\" ctx=\"40\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 89, 770, 89, 770, 101, 688, 101\" title=\"Country = China\" ctx=\"41\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 102, 770, 102, 770, 115, 688, 115\" title=\"Country = Finland\" ctx=\"42\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 115, 770, 115, 770, 128, 688, 128\" title=\"Country = France\" ctx=\"43\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 128, 770, 128, 770, 141, 688, 141\" title=\"Country = Germany\" ctx=\"44\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 141, 770, 141, 770, 154, 688, 154\" title=\"Country = Italy\" ctx=\"45\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 155, 770, 155, 770, 167, 688, 167\" title=\"Country = Japan\" ctx=\"46\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 168, 770, 168, 770, 181, 688, 181\" title=\"Country = Korea\" ctx=\"47\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 181, 770, 181, 770, 194, 688, 194\" title=\"Country = Mexico\" ctx=\"48\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 194, 770, 194, 770, 207, 688, 207\" title=\"Country = Netherlands\" ctx=\"49\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 207, 770, 207, 770, 220, 688, 220\" title=\"Country = Singapore\" ctx=\"50\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 221, 770, 221, 770, 233, 688, 233\" title=\"Country = Spain\" ctx=\"51\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 234, 770, 234, 770, 247, 688, 247\" title=\"Country = Sweden\" ctx=\"52\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 247, 770, 247, 770, 260, 688, 260\" title=\"Country = Switzerland\" ctx=\"53\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 260, 770, 260, 770, 273, 688, 273\" title=\"Country = United Kingdom\" ctx=\"54\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"legendLabel\" shape=\"POLY\" coords=\"688, 273, 770, 273, 770, 286, 688, 286\" title=\"Country = United States\" ctx=\"55\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"numericAxisTitle\" shape=\"POLY\" coords=\"9, 186, 9, 141, 22, 141, 22, 186\" tabIndex=\"-1\"><area class=\"chart_area\" type=\"ordinalAxisTitle\" shape=\"POLY\" coords=\"375, 333, 398, 333, 398, 346, 375, 346\" ctx=\"56\" tabIndex=\"-1\" isChartTitle=\"true\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"ordinalAxisLabel\" shape=\"POLY\" coords=\"171, 318, 195, 318, 195, 331, 171, 331\" title=\"Year = 2005\" ctx=\"32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"ordinalAxisLabel\" shape=\"POLY\" coords=\"307, 318, 331, 318, 331, 331, 307, 331\" title=\"Year = 2006\" ctx=\"33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"ordinalAxisLabel\" shape=\"POLY\" coords=\"443, 318, 468, 318, 468, 331, 443, 331\" title=\"Year = 2007\" ctx=\"34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"ordinalAxisLabel\" shape=\"POLY\" coords=\"578, 318, 602, 318, 602, 331, 578, 331\" title=\"Year = 2004\" ctx=\"35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"642, 314, 642, 247, 647, 247, 647, 314\" title=\"Year = 2004 &#10;Country = United States &#10;Revenue = $110,834,974.32\" ctx=\"135::55::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"506, 314, 506, 238, 512, 238, 512, 314\" title=\"Year = 2007 &#10;Country = United States &#10;Revenue = $126,305,726.63\" ctx=\"134::55::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"370, 314, 370, 214, 376, 214, 376, 314\" title=\"Year = 2006 &#10;Country = United States &#10;Revenue = $164,986,189.21\" ctx=\"133::55::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"234, 314, 234, 234, 240, 234, 240, 314\" title=\"Year = 2005 &#10;Country = United States &#10;Revenue = $131,677,071.69\" ctx=\"132::55::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"636, 314, 636, 289, 642, 289, 642, 314\" title=\"Year = 2004 &#10;Country = United Kingdom &#10;Revenue = $41,283,644.94\" ctx=\"131::54::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"500, 314, 500, 287, 506, 287, 506, 314\" title=\"Year = 2007 &#10;Country = United Kingdom &#10;Revenue = $45,281,813.88\" ctx=\"130::54::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"365, 314, 365, 279, 370, 279, 370, 314\" title=\"Year = 2006 &#10;Country = United Kingdom &#10;Revenue = $57,109,122.24\" ctx=\"129::54::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"229, 314, 229, 285, 234, 285, 234, 314\" title=\"Year = 2005 &#10;Country = United Kingdom &#10;Revenue = $47,515,163.57\" ctx=\"128::54::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"631, 314, 631, 135, 636, 135, 636, 314\" title=\"Year = 2004 &#10;Country = Switzerland &#10;Revenue = $295,529,033.90\" ctx=\"127::53::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"495, 314, 495, 103, 500, 103, 500, 314\" title=\"Year = 2007 &#10;Country = Switzerland &#10;Revenue = $349,478,076.60\" ctx=\"126::53::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"359, 314, 359, 22, 364, 22, 364, 314\" title=\"Year = 2006 &#10;Country = Switzerland &#10;Revenue = $482,114,950.82\" ctx=\"125::53::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"223, 314, 223, 84, 229, 84, 229, 314\" title=\"Year = 2005 &#10;Country = Switzerland &#10;Revenue = $380,789,747.47\" ctx=\"124::53::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"625, 314, 625, 303, 630, 303, 630, 314\" title=\"Year = 2004 &#10;Country = Sweden &#10;Revenue = $17,780,084.81\" ctx=\"123::52::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"489, 314, 489, 300, 494, 300, 494, 314\" title=\"Year = 2007 &#10;Country = Sweden &#10;Revenue = $23,089,905.72\" ctx=\"122::52::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"353, 314, 353, 297, 359, 297, 359, 314\" title=\"Year = 2006 &#10;Country = Sweden &#10;Revenue = $28,629,690.81\" ctx=\"121::52::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"217, 314, 217, 300, 223, 300, 223, 314\" title=\"Year = 2005 &#10;Country = Sweden &#10;Revenue = $22,770,212.11\" ctx=\"120::52::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"619, 314, 619, 302, 625, 302, 625, 314\" title=\"Year = 2004 &#10;Country = Spain &#10;Revenue = $20,230,164.18\" ctx=\"119::51::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"483, 314, 483, 295, 489, 295, 489, 314\" title=\"Year = 2007 &#10;Country = Spain &#10;Revenue = $31,586,471.26\" ctx=\"118::51::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"347, 314, 347, 289, 353, 289, 353, 314\" title=\"Year = 2006 &#10;Country = Spain &#10;Revenue = $41,467,572.14\" ctx=\"117::51::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"212, 314, 212, 297, 217, 297, 217, 314\" title=\"Year = 2005 &#10;Country = Spain &#10;Revenue = $27,822,178.46\" ctx=\"116::51::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"613, 314, 613, 295, 619, 295, 619, 314\" title=\"Year = 2004 &#10;Country = Singapore &#10;Revenue = $31,123,033.44\" ctx=\"115::50::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"478, 314, 478, 294, 483, 294, 483, 314\" title=\"Year = 2007 &#10;Country = Singapore &#10;Revenue = $33,670,543.85\" ctx=\"114::50::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"342, 314, 342, 287, 347, 287, 347, 314\" title=\"Year = 2006 &#10;Country = Singapore &#10;Revenue = $43,997,353.59\" ctx=\"113::50::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"206, 314, 206, 291, 211, 291, 211, 314\" title=\"Year = 2005 &#10;Country = Singapore &#10;Revenue = $37,519,215.28\" ctx=\"112::50::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"608, 314, 608, 299, 613, 299, 613, 314\" title=\"Year = 2004 &#10;Country = Netherlands &#10;Revenue = $25,243,944.19\" ctx=\"111::49::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"472, 314, 472, 294, 477, 294, 477, 314\" title=\"Year = 2007 &#10;Country = Netherlands &#10;Revenue = $33,459,084.00\" ctx=\"110::49::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"336, 314, 336, 288, 341, 288, 341, 314\" title=\"Year = 2006 &#10;Country = Netherlands &#10;Revenue = $42,550,836.35\" ctx=\"109::49::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"200, 314, 200, 295, 206, 295, 206, 314\" title=\"Year = 2005 &#10;Country = Netherlands &#10;Revenue = $31,959,640.39\" ctx=\"108::49::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"602, 314, 602, 300, 607, 300, 607, 314\" title=\"Year = 2004 &#10;Country = Mexico &#10;Revenue = $22,359,707.90\" ctx=\"107::48::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"466, 314, 466, 294, 472, 294, 472, 314\" title=\"Year = 2007 &#10;Country = Mexico &#10;Revenue = $32,341,116.79\" ctx=\"106::48::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"330, 314, 330, 283, 336, 283, 336, 314\" title=\"Year = 2006 &#10;Country = Mexico &#10;Revenue = $50,770,840.19\" ctx=\"105::48::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"194, 314, 194, 292, 200, 292, 200, 314\" title=\"Year = 2005 &#10;Country = Mexico &#10;Revenue = $35,589,920.02\" ctx=\"104::48::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"596, 314, 596, 293, 602, 293, 602, 314\" title=\"Year = 2004 &#10;Country = Korea &#10;Revenue = $34,972,686.75\" ctx=\"103::47::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"460, 314, 460, 291, 466, 291, 466, 314\" title=\"Year = 2007 &#10;Country = Korea &#10;Revenue = $37,861,828.65\" ctx=\"102::47::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"325, 314, 325, 284, 330, 284, 330, 314\" title=\"Year = 2006 &#10;Country = Korea &#10;Revenue = $48,993,648.20\" ctx=\"101::47::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"189, 314, 189, 288, 194, 288, 194, 314\" title=\"Year = 2005 &#10;Country = Korea &#10;Revenue = $42,487,248.13\" ctx=\"100::47::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"591, 314, 591, 283, 596, 283, 596, 314\" title=\"Year = 2004 &#10;Country = Japan &#10;Revenue = $52,035,850.83\" ctx=\"99::46::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"455, 314, 455, 282, 460, 282, 460, 314\" title=\"Year = 2007 &#10;Country = Japan &#10;Revenue = $53,138,382.31\" ctx=\"98::46::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"319, 314, 319, 270, 324, 270, 324, 314\" title=\"Year = 2006 &#10;Country = Japan &#10;Revenue = $73,162,203.83\" ctx=\"97::46::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"183, 314, 183, 279, 188, 279, 188, 314\" title=\"Year = 2005 &#10;Country = Japan &#10;Revenue = $58,251,511.01\" ctx=\"96::46::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"585, 314, 585, 301, 590, 301, 590, 314\" title=\"Year = 2004 &#10;Country = Italy &#10;Revenue = $22,227,856.92\" ctx=\"95::45::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"449, 314, 449, 294, 454, 294, 454, 314\" title=\"Year = 2007 &#10;Country = Italy &#10;Revenue = $33,788,864.66\" ctx=\"94::45::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"313, 314, 313, 286, 319, 286, 319, 314\" title=\"Year = 2006 &#10;Country = Italy &#10;Revenue = $45,622,153.53\" ctx=\"93::45::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"177, 314, 177, 295, 183, 295, 183, 314\" title=\"Year = 2005 &#10;Country = Italy &#10;Revenue = $31,113,988.15\" ctx=\"92::45::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"579, 314, 579, 289, 585, 289, 585, 314\" title=\"Year = 2004 &#10;Country = Germany &#10;Revenue = $41,462,245.81\" ctx=\"91::44::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"443, 314, 443, 289, 449, 289, 449, 314\" title=\"Year = 2007 &#10;Country = Germany &#10;Revenue = $41,352,298.31\" ctx=\"90::44::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"307, 314, 307, 281, 313, 281, 313, 314\" title=\"Year = 2006 &#10;Country = Germany &#10;Revenue = $55,037,217.04\" ctx=\"89::44::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"172, 314, 172, 288, 177, 288, 177, 314\" title=\"Year = 2005 &#10;Country = Germany &#10;Revenue = $43,631,063.98\" ctx=\"88::44::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"573, 314, 573, 283, 579, 283, 579, 314\" title=\"Year = 2004 &#10;Country = France &#10;Revenue = $50,546,272.09\" ctx=\"87::43::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"438, 314, 438, 287, 443, 287, 443, 314\" title=\"Year = 2007 &#10;Country = France &#10;Revenue = $43,928,088.57\" ctx=\"86::43::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"302, 314, 302, 281, 307, 281, 307, 314\" title=\"Year = 2006 &#10;Country = France &#10;Revenue = $53,967,275.85\" ctx=\"85::43::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"166, 314, 166, 286, 171, 286, 171, 314\" title=\"Year = 2005 &#10;Country = France &#10;Revenue = $45,745,704.79\" ctx=\"84::43::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"568, 314, 568, 298, 573, 298, 573, 314\" title=\"Year = 2004 &#10;Country = Finland &#10;Revenue = $27,206,118.41\" ctx=\"83::42::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"432, 314, 432, 293, 437, 293, 437, 314\" title=\"Year = 2007 &#10;Country = Finland &#10;Revenue = $35,396,299.54\" ctx=\"82::42::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"296, 314, 296, 286, 301, 286, 301, 314\" title=\"Year = 2006 &#10;Country = Finland &#10;Revenue = $45,967,540.48\" ctx=\"81::42::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"160, 314, 160, 293, 166, 293, 166, 314\" title=\"Year = 2005 &#10;Country = Finland &#10;Revenue = $35,485,794.15\" ctx=\"80::42::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"562, 314, 562, 285, 567, 285, 567, 314\" title=\"Year = 2004 &#10;Country = China &#10;Revenue = $48,615,406.63\" ctx=\"79::41::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"426, 314, 426, 283, 432, 283, 432, 314\" title=\"Year = 2007 &#10;Country = China &#10;Revenue = $50,570,397.61\" ctx=\"78::41::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"290, 314, 290, 271, 296, 271, 296, 314\" title=\"Year = 2006 &#10;Country = China &#10;Revenue = $70,569,951.66\" ctx=\"77::41::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"154, 314, 154, 281, 160, 281, 160, 314\" title=\"Year = 2005 &#10;Country = China &#10;Revenue = $54,721,687.35\" ctx=\"76::41::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"556, 314, 556, 289, 562, 289, 562, 314\" title=\"Year = 2004 &#10;Country = Canada &#10;Revenue = $41,468,882.87\" ctx=\"75::40::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"420, 314, 420, 282, 426, 282, 426, 314\" title=\"Year = 2007 &#10;Country = Canada &#10;Revenue = $53,511,041.09\" ctx=\"74::40::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"285, 314, 285, 273, 290, 273, 290, 314\" title=\"Year = 2006 &#10;Country = Canada &#10;Revenue = $67,341,094.59\" ctx=\"73::40::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"149, 314, 149, 284, 154, 284, 154, 314\" title=\"Year = 2005 &#10;Country = Canada &#10;Revenue = $49,366,410.09\" ctx=\"72::40::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"551, 314, 551, 303, 556, 303, 556, 314\" title=\"Year = 2004 &#10;Country = Brazil &#10;Revenue = $17,566,891.21\" ctx=\"71::39::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"415, 314, 415, 301, 420, 301, 420, 314\" title=\"Year = 2007 &#10;Country = Brazil &#10;Revenue = $21,447,899.23\" ctx=\"70::39::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"279, 314, 279, 296, 284, 296, 284, 314\" title=\"Year = 2006 &#10;Country = Brazil &#10;Revenue = $28,939,868.92\" ctx=\"69::39::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"143, 314, 143, 300, 148, 300, 148, 314\" title=\"Year = 2005 &#10;Country = Brazil &#10;Revenue = $22,580,246.05\" ctx=\"68::39::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"409, 314, 409, 302, 414, 302, 414, 314\" title=\"Year = 2007 &#10;Country = Belgium &#10;Revenue = $19,822,994.69\" ctx=\"67::38::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"273, 314, 273, 297, 279, 297, 279, 314\" title=\"Year = 2006 &#10;Country = Belgium &#10;Revenue = $27,345,821.17\" ctx=\"66::38::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"137, 314, 137, 301, 143, 301, 143, 314\" title=\"Year = 2005 &#10;Country = Belgium &#10;Revenue = $21,554,248.84\" ctx=\"65::38::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"539, 314, 539, 306, 545, 306, 545, 314\" title=\"Year = 2004 &#10;Country = Austria &#10;Revenue = $13,866,004.52\" ctx=\"64::37::35\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"403, 314, 403, 301, 409, 301, 409, 314\" title=\"Year = 2007 &#10;Country = Austria &#10;Revenue = $21,981,766.43\" ctx=\"63::37::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"267, 314, 267, 297, 273, 297, 273, 314\" title=\"Year = 2006 &#10;Country = Austria &#10;Revenue = $28,348,967.66\" ctx=\"62::37::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"132, 314, 132, 302, 137, 302, 137, 314\" title=\"Year = 2005 &#10;Country = Austria &#10;Revenue = $19,343,686.48\" ctx=\"61::37::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"398, 314, 398, 296, 403, 296, 403, 314\" title=\"Year = 2007 &#10;Country = Australia &#10;Revenue = $29,323,674.25\" ctx=\"60::36::34\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"262, 314, 262, 290, 267, 290, 267, 314\" title=\"Year = 2006 &#10;Country = Australia &#10;Revenue = $38,968,802.62\" ctx=\"59::36::33\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"><area class=\"chart_area\" type=\"chartElement\" shape=\"POLY\" coords=\"126, 314, 126, 302, 131, 302, 131, 314\" title=\"Year = 2005 &#10;Country = Australia &#10;Revenue = $19,270,852.15\" ctx=\"58::36::32\" tabIndex=\"-1\" onmouseup=\"preSelectNode(event);\"></map><span tabIndex=\"0\"><img name=\"chartN0DD7A018.0C5F76FC\" style=\"padding-left: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;\" class=\"c_THIS_ ch\" LID=\"null\" rsvpChart=\"true\" src=\"http://9.119.141.234:88/ibmcognos/cgi-bin/cognos.cgi?SM=query&amp;search=storeID(%22iE53CDE4BD6D741EFA095674EEDACC062%22)&amp;SA=propEnum,properties&amp;ITEM=data&amp;EA=&amp;SS=queryOptions,options&amp;dataEncoding=MIME&amp;ES=&amp;EM=\" width=\"790\" height=\"350\" usemap=\"#rsvptt0\" border=\"0\"><script language=\"javascript\" type=\"text/javascript\">\n" +
//                "var graphicSrcN0DD7A018_0C5F76FC = document.images[\"chartN0DD7A018.0C5F76FC\"].src;\n" +
//                "displayChart(\"chartN0DD7A018.0C5F76FC\", \"\", false, false);\n" +
//                "</script></span></td></tr></table></td></tr></table>\n" +
//                "</body>\n" +
//                "</html>";
//    }



    public ReportHtmlUtil(String html) {
        this.source = html;
        this.document = Jsoup.parse(source);
    }

    public String getHeaderContent(Document source) {
        return source.select("header").first().html();
    }

    public List<HashMap<String, String>> getCssImports() {
        List cssImports = new ArrayList();
        Iterator it = document.select("head>link").iterator();
        while (it.hasNext()) {
            Element element = (Element) it.next();
            if (element.attr("type").equals("text/css") &&
                    element.hasAttr("xmlns:rsext")) {
                HashMap<String, String> hash = new HashMap<String, String>();
                hash.put("namespace", element.attr("xmlns:rsext"));
                hash.put("href", element.attr("href"));
                cssImports.add(hash);
            }
        }

        return cssImports;
    }

    public List<HashMap<String, String>> getJavascriptSnippets() {
        List cssImports = new ArrayList();
        Iterator it = document.select("head>script").iterator();
        while (it.hasNext()) {
            Element element = (Element) it.next();
            if (element.attr("type").equals("text/javascript")&&
                    element.hasAttr("xmlns:rsext")) {
                HashMap<String, String> hash = new HashMap<String, String>();
                hash.put("namespace", element.attr("xmlns:rsext"));
                hash.put("javascript", element.html());
                cssImports.add(hash);
            }
        }

        return cssImports;
    }

    public String getBodyContent() {
        return document.select("body").first().html();
    }

//    public static void main(String[] args) {
//        ReportHtmlUtil util = new ReportHtmlUtil(sampleHtml());
//        System.out.println(util.transform());
//    }

    public String transform() {
        String cssImports = handleCss();
        String jsCode = handleJavascripts();
        String origBody = getBodyContent();
        return  cssImports + jsCode + origBody;
    }

    private String handleCss() {
        StringBuffer sb = new StringBuffer();
        sb.append("<script type=\"text/javascript\">\n");
        sb.append(cssFunction());
        List<HashMap<String, String>> cssImports = getCssImports();
        for (HashMap<String, String> css : cssImports) {
            String javascriptCode = translateToJavascript(css);
            sb.append(javascriptCode).append("\n");
        }
        sb.append("</script>\n");
        return sb.toString();
    }

    private String translateToJavascript(HashMap<String, String> css) {
        return "loadCSS(\""+css.get("href")+"\")";
    }

    private String cssFunction() {
        return "function loadCSS(filename){ \n" +
                "\n" +
                "       var file = document.createElement(\"link\")\n" +
                "       file.setAttribute(\"rel\", \"stylesheet\")\n" +
                "       file.setAttribute(\"type\", \"text/css\")\n" +
                "       file.setAttribute(\"href\", filename)\n" +
                "\n" +
                "       if (typeof file !== \"undefined\")\n" +
                "          document.getElementsByTagName(\"head\")[0].appendChild(file)\n" +
                "    }\n";
    }


    private String handleJavascripts() {
        StringBuffer sb = new StringBuffer();
        sb.append("<script xmlns:rsext=\"xalan://com.cognos.reportserver.ext.RSExt\" language=\"javascript\" type=\"text/javascript\">\n");

        List<HashMap<String, String>> code = getJavascriptSnippets();
        for (HashMap<String, String> hash : code) {
            String namespace = hash.get("namespace");
            String js = hash.get("javascript");
            sb.append(js).append("\n");
        }
        sb.append("</script>\n");
        return sb.toString();
    }
}
